﻿Imports BUS
Imports DTO

Public Class frmTraSach

    Dim ds_uscontrol As New List(Of UserChiTietSach)

    Public Sub frmTraSach_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cbbChiTiet.DataSource = PhieuMuon_BUS.loadPhieuMuon
        cbbChiTiet.DisplayMember = "mamuon"
        cbbChiTiet.ValueMember = "mamuon"
    End Sub

    Public Sub cbbChiTiet_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbbChiTiet.SelectedIndexChanged
        gpDSMuon.Controls.Clear()

        Dim pm As PhieuMuon_DTO = CType(cbbChiTiet.SelectedItem, PhieuMuon_DTO)

        lblNgayMuon.Text = pm.ngayMuon
        lblNgayTra.Text = pm.ngayHetHan

        Dim dt As DataTable = ChiTietPhieuMuon_BUS.loadCTPhieuMuon(pm.maMuon)

        Dim x As Integer = 100
        Dim y As Integer = 90
        Dim i As Integer = 0

        For Each r As DataRow In dt.Rows
            Dim us As New UserChiTietSach
            us.btnSach.Tag = r(0)
            us.btnSach.BackgroundImage = Image.FromFile(r(1).ToString)
            us.BackgroundImageLayout = ImageLayout.Stretch
            us.lblTinhTrang.Text = "Số lượng: " + r(2).ToString
            us.btnSach.Name = r(3)
            us.Width = 65
            us.Height = 90
            us.Top = 20
            us.Left = 10 + (y * i)
            i = i + 1
            ds_uscontrol.Add(us)
            Me.gpDSMuon.Controls.Add(us)
            AddHandler us.btnSach.Click, AddressOf myButtonClick
        Next

    End Sub

    Private Sub myButtonClick(ByVal sender As Object, ByVal e As EventArgs)
        Dim bt As Button = CType(sender, Button)
        Dim f As New frmSLSachTra(bt)
        f.ShowDialog()
    End Sub

    Private Sub btnDSTra_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDSTra.Click
        Dim f As New frmDSTra
        f.ShowDialog()
    End Sub
End Class